package org.vectrics.common.db;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import org.apache.log4j.Logger;
import org.vectrics.company.Sector;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.user.PersonEducationType;

public class DisplayUtils {
	private static final Logger log = Logger.getLogger(DisplayUtils.class);
	
	public static Collection<CodeAndDescription> sectorTypesToCoded(Collection sectorTypes, Locale locale) {
		Collection<CodeAndDescription> newList = new ArrayList<CodeAndDescription>();
		Iterator iter = sectorTypes.iterator();
		while (iter.hasNext()) {
			Sector sectorType = (Sector)iter.next();
			CodeAndDescription codeObj = new CodeAndDescription();
			codeObj.setCode(sectorType.getCode());
			codeObj.setDescription(CoreServiceLocator.getPhraseProvider()
					.getMessage(sectorType.getDescriptionCode(), locale));
			newList.add(codeObj);
		}
		return(newList);
	}

	/**
	 * Fill an array with coded objects representing person education types.
	 * @param allPersonEducationTypes
	 * @param locale
	 * @return
	 */
	public static Collection<CodeAndDescription> personEducationTypesToCoded(Collection allPersonEducationTypes, Locale locale) {	
		Collection<CodeAndDescription> newList = new ArrayList<CodeAndDescription>();
		Iterator iter = allPersonEducationTypes.iterator();
		while (iter.hasNext()) {
			PersonEducationType personEducationType = (PersonEducationType)iter.next();
			
			CodeAndDescription codeObj = new CodeAndDescription();
			codeObj.setCode(personEducationType.getCode());
			codeObj.setDescription(CoreServiceLocator.getPhraseProvider().getMessage(personEducationType.getDescriptionCode(), locale));
			log.info("Eduction code object: " + codeObj);
			newList.add(codeObj);
		}
		return(newList);
	}

}
